package vip.liux.contracts.shared.enums.pay;

import vip.liux.core.enums.IEnum;

import java.util.Objects;

public enum PayOrderStatus implements IEnum {

    WAITING(0, "未支付"),
    SUCCESS(10, "支付成功"),
    REFUND(20, "已退款"),
    CLOSED(30, "支付关闭"), // 注意：全部退款后，还是 REFUND 状态
    ;

    /**
     * 类型
     */
    private final int value;
    /**
     * 名字
     */
    private final String desc;

    PayOrderStatus(int value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    /**
     * 判断是否等待支付
     *
     * @param status 状态
     * @return 是否等待支付
     */
    public static boolean isWaiting(PayOrderStatus status) {
        return Objects.equals(status, WAITING);
    }

    /**
     * 判断是否支付成功
     *
     * @param status 状态
     * @return 是否支付成功
     */
    public static boolean isSuccess(PayOrderStatus status) {
        return Objects.equals(status, SUCCESS);
    }

    public static boolean isSuccess(Integer status) {
        return Objects.equals(status, SUCCESS.getValue());
    }

    /**
     * 判断是否已退款
     *
     * @param status 状态
     * @return 是否已退款
     */
    public static boolean isRefund(PayOrderStatus status) {
        return Objects.equals(status, REFUND);
    }

    public static boolean isRefund(Integer status) {
        return Objects.equals(status, REFUND.getValue());
    }

    /**
     * 判断是否支付成功或者已退款
     *
     * @param status 状态
     * @return 是否支付成功或者已退款
     */
    public static boolean isSuccessOrRefund(PayOrderStatus status) {
        return Objects.equals(status,
                SUCCESS) || Objects.equals(status, REFUND);
    }

    /**
     * 判断是否支付关闭
     *
     * @param status 状态
     * @return 是否支付关闭
     */
    public static boolean isClosed(PayOrderStatus status) {
        return Objects.equals(status, CLOSED);
    }

    public static boolean isClosed(Integer status) {
        return Objects.equals(status, CLOSED.getValue());
    }

    @Override
    public int getValue() {
        return value;
    }

    @Override
    public String getDesc() {
        return desc;
    }

}
